<template>
  <div class="h1">
    <div class="revise">
      <el-form
        :model="ruleForm"
        status-icon
        ref="ruleForm"
        label-width="120px"
        class="demo-ruleForm"
      >
        <el-form-item label="用户名：" prop="pass">
          <el-input v-model="username" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="请输入原密码：" prop="pass">
          <el-input
            type="password"
            v-model="ruleForm.Oldpass"
            autocomplete="off"
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item label="请输入新密码：" prop="pass">
          <el-input
            type="password"
            v-model="ruleForm.Newpass"
            autocomplete="off"
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item label="确认新密码：" prop="checkPass">
          <el-input
            type="password"
            v-model="ruleForm.checkPass"
            autocomplete="off"
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >提交</el-button
          >
          <el-button @click="resetForm('ruleForm')">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
      ruleForm: {
        Oldpass: '',
        Newpass: '',
        checkPass: ''
      },
      username: ''
    }
  },
  created () {
    this.index()
  },
  methods: {
    index () {
      const item = JSON.parse(sessionStorage.getItem('user'))
      console.log(item);
      this.username = item.username
    },
    // 失去焦点触发：检测原密码是否正确
    submitForm () {
      const that = this
      this.$http({
        method: 'POST',
        url: '/lk/lk/verify',
        data: {
          username: this.username,
          oldPassword: this.ruleForm.Oldpass,
          newPassword: this.ruleForm.Newpass
        }
      }).then(function (response) {
        if (response.data.status == 0) {
          alert(response.data.message)
          that.$router.push('/')
        } else if (response.data.status == 1) {
          alert(response.data.message)
        }
      })
    },
    // 提交表单数据
    // submitForm () {

    // },
    // 重置表单
    resetForm () {

    }
  }
}
</script>

<style lang="less" scoped>
html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  background-color: pink;
}
.h1 {
  width: 100%;
  height: 100%;
  .revise {
    width: 400px;
    height: 300px;
    margin: 0 auto;
    background-color: pink;
    .el-form {
      margin: 100px auto;
      .el-form-item {
        .el-input {
          width: 250px;
          text-align: center;
        }
      }
    }
  }
}
</style>